#pragma once
#include <stdlib.h>
#include <stdio.h>
#include "Vector3.h"
#ifdef WIN32
#include <GL/glut.h>
#endif
#ifdef __APPLE__
#include <GLUT/glut.h>
#endif
#include "Frustum.h"

namespace lib3dw
{
	class Camera 
	{
	public:
		Camera(Vector3 i_eye, Vector3 i_look, Vector3 i_up, float i_near, float i_far, float i_aspect, float i_angle=45.0f);
		~Camera() {}

		void ResizeWindow(int ww, int wh);
		void Move(float hAngle, float vAngle);
		void MoveHorizontal(float amount);
		void MoveVertical(float amount);
		void Rotate(float hAngle, float vAngle);
		void RotateHorizontal(float amount);
		void RotateVertical(float amount);
		void Zoom(float amount);
		void Reset(void);
		Vector3 GetLook() const;
		Vector3 GetEye() const;
		Vector3 GetUp() const;
		float GetPhi() const;
		float GetTheta() const;
		float GetNear() const;
		float GetFar() const;
		float GetAngle() const;
		float GetAspect() const;
		float TransformMouseX();
		float TransformMouseY();
		void SetPosition(Vector3 i_eye, Vector3 i_look);
		Frustum* GetFrustum();

	private:
		void SetViewport();
		void SetPerspective();
		void SetOrthogonal();
		void SetModelView();
		Vector3 CalculateN() const;
		Vector3 CalculateU() const;
		Vector3 CalculateV() const;
		Vector3 CalculateXYZ() const;
		Vector3 look, defaultLook;
		Vector3 eye, defaultEye;
		Vector3 up, defaultUp;
		Frustum* frustum;
		float theta;
		float phi;
		float weight;
		float aspect;
		float nearPlane;
		float farPlane;
		float angle;
		int windowWidth;
		int windowHeight;
		static const float PI;
		static const float _PI_180;
		static const float _180_PI;
		static const float defaultAspect;
	};
}